package com.burges.net.dataStream.codeRuler.transform.SingleDataStream

import org.apache.flink.api.common.functions.MapFunction
import org.apache.flink.streaming.api.scala.{DataStream, StreamExecutionEnvironment, _}

/**
  * 创建人    BurgessLee
  * 创建时间   2020/1/26
  * 描述     MapFunction操作
  */
object MapTransformDemo {

	def main(args: Array[String]): Unit = {
		val env = StreamExecutionEnvironment.getExecutionEnvironment

		val dataStream: DataStream[(String, Int)] = env.fromElements(("a",1), ("b",2), ("c", 3), ("d", 4))
		//指定map计算表达式
		val mapStream: DataStream[(String, Int)] = dataStream.map(t => (t._1, t._2+1))

		mapStream.print()

		//使用方式2
		// 使用Java语言开发的时候较多
		val mapStream2: DataStream[(String, Int)] = dataStream.map(new MapFunction[(String, Int), (String, Int)] {
			override def map(t: (String, Int)): (String, Int) = {
				(t._1, t._2 + 1)
			}
		})
		mapStream2.print()
	}

}
